package com.sky.wsp.jboot.controller;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sky.wsp.jboot.model.User;
import io.jboot.app.JbootApplication;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/")
public class IndexController extends JbootController {

    public static void main(String[] args) {
        JbootApplication.run(args);
    }

    public void index() {
        renderText("Hello World Jboot");
    }

    /**
     *  http://localhost:8080/dbtest
     */
    public void dbtest(){
        List<Record> records = Db.find("select * from user");
        renderText(Arrays.toString(records.toArray()));
    }

    /**
     *  http://localhost:8080/doSave?login_name=lisi&password=123123
     */
    public void doSave() {
        String loginName = getPara("login_name");
        String password = getPara("password");

        User user = new User();
        user.setLoginName(loginName);
        user.setPassword(password);

        user.save();

        System.out.println("================== doSave user id : " + user.getId());
        renderText("================== doSave user id : " + user.getId());

//        redirect("/user");
    }
}